package com.kehongborui.fliggy.util;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * @author zhang peng yang ming
 * @CopyRight (C) http://www.csdn.com
 * @brief
 * @email 122162005@qq.com
 * @date 2018-08-23
 */
public class CommonUtils {
    /**
     * 生成订单编号，uuid类型
     * @return
     */
    public static String generateOrderId() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }
    public static String token() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    /**
     * 生成订单编号，时间戳类型
     * @return
     */
    public static String generateOrderId_() {
        return ("" + System.currentTimeMillis()).substring(2) + (int)(Math.random() * 10);
    }

    public static Integer getStopTime(String depTime, String arrTime) {
        SimpleDateFormat format = new SimpleDateFormat("HH:mm");
        try {
            Date dep = format.parse(depTime);
            Date arr = format.parse(arrTime);
            if (dep.getTime() < arr.getTime()) {
                return (int) ((dep.getTime() + 24 * 60 * 60 * 1000 - arr.getTime()) / (1000 * 60));
            } else {
                return (int) ((dep.getTime() - arr.getTime()) / (1000 * 60));
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return 0;
    }

    /**
     * 判断对象是否为空
     * @param target
     * @return
     */
    public static boolean isEmpty(Object target) {
        return target == null || "".equals(target);
    }

    public static void main(String[] args) {
//        StringBuffer buffer = new StringBuffer();
//        buffer.append("333");
//        System.out.println("/login?redirectURL=" + buffer.toString()+ "hell");
//        String r = "";
//        System.out.println("".equals(r));
//        short s1 = 1; s1 = s1 + 1;
//        short s1 = 1; s1 += 1;
////        Integer a = 1;
//////        System.out.println(generateOrderId());
////        System.out.println(getStopTime("02:13", "23:16"));
//        new Thread(() -> {
//            System.out.println(httpDownload("http://10.3.2.218:8080/goldacntDemo/one/02.mp4", "E:\\video\\part01\\02.mp4"));
//        }).start();
//        new Thread(() -> {
//            System.out.println(httpDownload("http://10.3.2.218:8080/goldacntDemo/one/03.mp4", "E:\\video\\part01\\03.mp4"));
//        }).start();
//        new Thread(() -> {
//            System.out.println(httpDownload("http://10.3.2.218:8080/goldacntDemo/one/04.mp4", "E:\\video\\part01\\04.mp4"));
//        }).start();
//        new Thread(() -> {
//            System.out.println(httpDownload("http://10.3.2.218:8080/goldacntDemo/one/05.mp4", "E:\\video\\part01\\05.mp4"));
//        }).start();
    }



}
